package com.example.planstudio;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;



        import android.content.Context;
        import android.view.LayoutInflater;
        import android.view.View;
        import android.view.ViewGroup;
        import android.widget.BaseAdapter;
        import android.widget.ImageView;
        import android.widget.LinearLayout;
        import android.widget.TextView;

        import java.util.ArrayList;
        import java.util.List;

//
//        import com.example.myapplication.R;
//        import com.example.myapplication.MsgInfo;
//import createproject.zhuoxin.edu.housekeeperdemo1.R;
//import createproject.zhuoxin.edu.housekeeperdemo1.entity.MsgInfo;

/**
 * Created by Administrator on 2016/5/19 0019.
 */
public class ListviewAdapt extends BaseAdapter {

    private Context context;
    private List<MsgInfo> datas = new ArrayList<>();

//    public String getServer_name() {
//        return server_name;
//    }

//    public void setServer_name(String server_name) {
//        this.server_name = server_name;
//    }

//    public String server_name="雪之下雪乃";
    public int server=2131230827;
    //2131165294
    public int client=2131230828;

    public void clear() {
        datas.clear();
        notifyDataSetChanged();
    }

    public int getServer() {
        return server;
    }

    public void setServer(int server) {
        this.server = server;
    }

    public int getClient() {
        return client;
    }

    public void setClient(int client) {
        this.client = client;
    }



    private ViewHolder viewHolder;

    public void addDataToAdapter(MsgInfo e) {
        datas.add(e);
    }
    public void addserver(int e) {
        server=e;
    }
    public ListviewAdapt(Context context) {
        this.context = context;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if (convertView == null) {

            LayoutInflater inflater = LayoutInflater.from(context);
            convertView = inflater.inflate(R.layout.item, null);
            viewHolder = new ViewHolder(convertView);

            convertView.setTag(viewHolder);

        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        String left = datas.get(position).getLeft_text();
        String right = datas.get(position).getRight_text();
        int server=this.server;
        int client=this.client;
        if (left == null) {
            viewHolder.text_right.setText(right);
            viewHolder.client.setImageResource(client);
            viewHolder.right.setVisibility(View.VISIBLE);
            viewHolder.left.setVisibility(View.INVISIBLE);
        }

        if (right == null) {
            viewHolder.text_left.setText(left);
//            server=2131165294;
            viewHolder.server.setImageResource(server);

//            viewHolder.server_name.setText(server_name);
            viewHolder.left.setVisibility(View.VISIBLE);
            viewHolder.right.setVisibility(View.INVISIBLE);
        }

        return convertView;

    }

//

    public static class ViewHolder {
        public View rootView;
        public TextView text_left;
        public ImageView server;
//        public TextView server_name;
        public ImageView client;
//        public TextView client_name;
        public LinearLayout left;
        public TextView text_right;
        public LinearLayout right;

        public ViewHolder(View rootView) {
            this.rootView = rootView;
            this.text_left = (TextView) rootView.findViewById(R.id.text_left);
            this.left = (LinearLayout) rootView.findViewById(R.id.left);
            this.text_right = (TextView) rootView.findViewById(R.id.text_right);
            this.right = (LinearLayout) rootView.findViewById(R.id.right);
//            server_name = (TextView) rootView.findViewById(R.id.server_name);
//            client_name = (TextView) rootView.findViewById(R.id.client_name);
            server = (ImageView) rootView.findViewById(R.id.server);
            client = (ImageView) rootView.findViewById(R.id.client);


        }

    }
}

